import request from '@utils/request'

// 提交表单信息
export function postFrom(data) {
  return request({
      url: '/business/elementFile',
      headers: {
          isToken: false
      },
      method: 'post',
      data: data
  })
}

// 修改表单信息
export function changeFrom(data) {
  return request({
      url: '/business/elementFile',
      headers: {
          isToken: false
      },
      method: 'put',
      data: data
  })
}

// 文件上传方法
export function files(file,type,graphicId) {
  var data = new FormData();
  data.append('file', file);
  data.append('type', type);
  data.append('elementId', graphicId);
  return request({
      url: '/resource/oss/upload',
      headers: {
          "Content-Type": "multipart/form-data",
          isToken: false
      },
      method: 'post',
      data:data,
      // onUploadProgress: function (e) {
      //   console.log('e:',e);
      // }
  })
}

// 删除要素文件
export function delFiles(fileId) {
  return request({
      url: `/business/elementFile/${fileId}`,
      headers: {
          isToken: false,
      },
      method: 'DELETE',
  })
}

// 查询空间要素详细信息
export function searchElement(elementId) {
  return request({
      url: `/business/elementFile/list`,
      headers: {
          isToken: false
      },
      method: 'get',
      params: {
          elementId: elementId
      }
  })
}

// 数据导入文件上传
export function vectorFiles(file,type) {
  var data = new FormData();
  data.append('file', file);
  data.append('type', type);
  return request({
      url: '/resource/oss/upload',
      headers: {
          "Content-Type": "multipart/form-data",
          isToken: false,
      },
      method: 'post',
      data:data,
  })
}

// 导入CAD
export function importCAD(file, epsg) {
  var data = new FormData();
  data.append('file', file);
  return request({
    url: '/business/element/upload/cad?epsg=' + epsg,
    headers: {
        "Content-Type": "multipart/form-data",
        isToken: false,
    },
    method: 'post',
    data:data,
  })
}

// 获取CAD需要提交数据
export function getSubCADData() {
  return request({
      url: '/business/element/epsg',
      headers: {
          isToken: false
      },
      method: 'get',
  })
}
